<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>盱眙供电局路线配置</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script src="../../js/jquery-ui-1.10.4.custom.min.js"></script>
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .ui-autocomplete {
            max-width:175px;
            max-height: 300px;
            overflow-x: auto;
            overflow-y: auto;
        }
    </style>
    <script>
        layui.use(['table', 'form', 'jquery', 'element','layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var layer=layui.layer;
            var user;
            var options = {
                elem: "#table",
                id: "modelReload",
                url: '/xuYiLine/findLinesInfo',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                loading: true,
                page: {
                    count: "count",
                    limit: 10,
                    limits: [10, 20,30,40,50],
                    layout: ['prev', 'page', 'next', 'skip', 'limit', 'count'],
                    prev: "上一页",
                    next: "下一页",
                    groups: 5
                },
                cols: [[ //表头
                	{field: 'name', title: '路线名称',align:'center',width: '30%'},
                    {field: 'createTime', title: '创建时间',align:'center',width: '30%'},
                    {field: 'operation', title: '操作',align:'center', toolbar: '#barDemo'}
                ]],
                done: function (res) {
                    // console.log(JSON.stringify(res));
                }
            };
    
    	$("#mgrName").autocomplete({
       	source : function( request, response ) {
        var key = $("#mgrName").val();
        var cityId=$("#cityId").val();
        var countyId=$("#countyId").val();
        var url = '/util/selectMgrNameLike';
        var param = {
            cityId : cityId,
            countyId : countyId,
         key : key
        };
                 $.ajax({
         type : 'post',
         async : false,
         url : url,
         data : param,
         success : function(json) {
          var data = json.data;
          source = [];
          for (var i = 0; i < data.length; i++) {
           source[i] = data[i].name;
          }
          console.log(source);
          response( source );
         },
         error : function() {
          layer.msg('系统异常，请联系管理员处理!');
         }
        }
        );
            },
       messages : { //message设置不出现匹配关键字的结果
        noResults : '',
        results : function() {
        }
       }
      });
    		
    		table.render(options);
    		table.on('tool(tableElement)', function (obj) {
                 var data = obj.data;
					 if (obj.event == 'modify') {
                    window.location.href = encodeURI('xuYiPathModify.html?lineId=' + encodeURIComponent(data.id));
                } else  {
                    if (obj.event == 'delete') {
                    	layer.confirm('您确定要删除该条数据吗？', {icon: 3, title: '提示'}, function (index) {
                            var url = "/xuYiLine/deleteLineInfo";
                            var param = {
                                lineId: data.id,
                                lineName: data.name
                            };
                            console.info(data.id);
                            $.ajax({
                                type: 'post',
                                data: param,
                                url: url,
                                success: function (json) {
                                    if (json.code == 0) {
                                        layer.open({
                                            content:"操作成功，待审核！",
                                            closeBtn:0,
                                            btn: ['确认'] //按钮
                                        }, function () {
                                            location.href = "xuYiPathManage.html";
                                        });
                                    }else {
                                       layer.msg(json.data.msg);
                                    }
                                }
                            });
                        });
                    }
                } 
            });
            //更新数据表
            $('#query').on('click', function () {

            	    var pathName=$("#pathName").val();
  	       			console.info(pathName);
  	  
  	       			var pathNameText = $("#pathNameText").val();
  	       			
  	       			if(isNull(pathNameText)){
  	       				console.info("xuanze");
  	       			}else{
  	       				console.info("tainxie");
  	       				pathName = pathNameText;
  	       			}
  	       			
  	       			if (pathName == null || pathName== "") {
                            layer.msg("路线名称不能为空");
                            return false;
                    }   
                    
                    if ("all"==pathName) {
                            pathName="";
                    }    
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    
                    //console.info(subStationName);
                    //table.render(options);
                    table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        lineName: pathName
                    }
                });
                layer.close(index);
                
            });
            
            $('#insert').on('click', function () {
                window.location.href = 'xuYiPathAdd.html';
            });

            
            //身份识别
            $(document).ready(function () {
            	qryPathName();
            });
            
            //
            function qryPathName() {
                var data;
                var url = '/xuYiLine/findLineNameList';
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                            if (data.length != null) {
                    		var options = '<option value="all">全部</option>';
                    			for (var i = 0; i < data.length; i++) {
                    				//console.info(data[i]);
                        			options += '<option value="' + data[i] + '">' + data[i] + '</option>';
                    			}
                    			$('#pathName').html(options);
                			} else {
                    			$('#pathName').html('暂无路线信息');
                			}
                form.render();
                            
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
            
            form.on('select(pathName)', function (data) {
                var subStationList=selectRegionName(data.value);
                appendSubStationNames(subStationList);
            });
            
            function selectRegionName(pathName) {
                var data;
                var url = '/smsArea/findRegionName?pathName=' + pathName;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
            
             function appendSubStationNames(data){
                if (data.length != null) {
                    var options = '<option value="all">全部</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i]+ '">' + data[i] + '</option>';
                    }
                    $('#subStationName').html(options);
                } else {
                    $('#subStationName').html('该路线下暂无点位');
                }
                form.render();
    		}
    
    			$("#pathNameText").autocomplete({
    			source : function(request, response) {
    			    console.info("---"+lineNameText);
    				var lineNameText = $("#pathNameText").val();
    				var url = '/xuYiLine/findLineNameList';
    				var param = {
    					lineName : lineNameText,
    				};
    				$.ajax({
    					type : 'post',
    					async : false,
    					url : url,
    					data : param,
    					success : function(json) {
    						var data = json.data;
    						source = [];
    						for (var i = 0; i < data.length; i++) {
    							source[i] = data[i];
    						}
    						console.log(source);
    						response(source);
    					},
    					error : function() {
    						layer.msg('系统异常，请联系管理员处理!');
    					}
    				}
    				);
    			},
    			messages : { //message设置不出现匹配关键字的结果
    				noResults : '',
    				results : function() {}
    			}
    		});
        });

    </script>
    <script type="text/html" id="barDemo">
        <a href="javascript:void(0)" lay-event="modify" id="modify">编辑</a>
		<a href="javascript:void(0)" lay-event="delete" id="delete">删除</a>
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
            <span class="layui-breadcrumb" lay-separator="|">
                     <a href="javascript:returnIndex2()">首页&nbsp;</a>
                  <a href="#">路线信息配置</a>
            </span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        
                        <div id= "regionChoose">
                    		<div class="layui-inline">
                            <label class="layui-form-label" style="width:120px;">路线:</label>
                            <div class="layui-input-block" style="width:180px;margin-left:120px;">
                                <select name="pathName" lay-filter="pathName" id="pathName">
                                    
                                </select>
                            </div>
                        </div>
                     <div class="layui-inline" >
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width:120px">路线名称:</label>
                            <div class="layui-input-block" style="width:180px;margin-left:120px;">
			                    <input type="text" name="pathNameText" id="pathNameText" required lay-verify="required"
			                           placeholder="请输入路线名称"
			                           autocomplete="off" class="layui-input">
			                </div>
                        </div>
                    </div>
                        <div class="layui-inline" pane="">
                            <button class="layui-btn layui-btn-normal" id="query">查&nbsp;询</button>
                            <button class="layui-btn layui-btn-normal" id="insert" >
                                <i class="layui-icon">&#xe608;</i> 添加
                            </button>
                            <!-- <button class="layui-btn layui-btn-normal" id="test" >
                                <i class="layui-icon">&#xe608;</i> 测试
                            </button> -->
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-table">
                <table id="table" lay-filter="tableElement"></table>
            </div>
        </div>
    </div>
</div>
</body>
</html>